package com.course.controller;

import android.graphics.Bitmap;

import com.course.model.req.Base64File;
import com.course.utils.ImageUtil;
import com.course.utils.web.HttpAction;
import com.course.utils.web.HttpReq;
import com.course.utils.web.HttpRespCallBack;
import com.course.utils.web.MapBuilder;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class UploadController {

    static UploadController instance;

    public static UploadController getInstance() {
        if (instance == null) {
            instance = new UploadController();
        }
        return instance;
    }


    public void uploadImg(String localPath, HttpRespCallBack httpRespCallBack) {
        HttpReq.getInstance().post(HttpAction.imagUpload.getValue(),
                new MapBuilder<String, Object>()
                        .add("data", ImageUtil.imageToBase64ByLocal(localPath))
                        .add("fileName", new File(localPath).getName())
                        .getMap(),
                httpRespCallBack);
    }
    public void uploadBitmap(Bitmap bitmap, HttpRespCallBack httpRespCallBack) {
        HttpReq.getInstance().post(HttpAction.imagUpload.getValue(),
                new MapBuilder<String, Object>()
                        .add("data", ImageUtil.bitmapToBase64(bitmap))
                        .add("fileName", System.currentTimeMillis()+".jpg")
                        .getMap(),
                httpRespCallBack);
    }


    public void uploadFils(String localPath,Bitmap bitmap, HttpRespCallBack httpRespCallBack) {

        List<Base64File> array = new ArrayList<>();
        Base64File video = new Base64File();
        video.setData(ImageUtil.imageToBase64ByLocal(localPath));
        video.setFileName(new File(localPath).getName());
        array.add(video);


        Base64File img = new Base64File();
        img.setData(ImageUtil.bitmapToBase64(bitmap));
        img.setFileName(System.currentTimeMillis()+".jpg");
        array.add(img);


        HttpReq.getInstance().post(HttpAction.imagUploads.getValue(),
                new MapBuilder<String, Object>()
                        .add("files", array)
                        .getMap(),
                httpRespCallBack);
    }




}
